package com.his.server.utils.main;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.StrutsStatics;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.ParameterAware;

import com.his.server.consts.ServerConsts;

public class BaseContext implements ServletRequestAware, ServletResponseAware,
		SessionAware, ParameterAware {

	protected static HttpServletRequest request;
	protected static HttpServletResponse response;
	protected static Map session;
	protected static Map parameters;
	protected static String connectFlag;

	/**
	 * setServletRequest
	 * 
	 * @param request
	 *            HttpServletRequest
	 */
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	/**
	 * setServletResponse
	 * 
	 * @param response
	 *            HttpServletResponse
	 */
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	/**
	 * setSession
	 * 
	 * @param session
	 *            Map
	 */
	public void setSession(Map session) {
		this.session = session;
	}

	/**
	 * setParameters
	 * 
	 * @param parameters
	 *            Map
	 */
	public void setParameters(Map parameters) {
		this.parameters = parameters;
	}
	 
	/**
	 * setAtribute
	 * 
	 * @param key
	 *            String
	 * @param value
	 *            String
	 */
	public static void setAtribute(String key, Object value) {
		session.put(key, value);
	}

	// /**
	// * setConnectFlag
	// * @param connectFlag String
	// */
	// public void setConnectFlag(String connectFlag) {
	// this.connectFlag = connectFlag;
	// }

	/**
	 * getServletRequest
	 * 
	 * @return request HttpServletRequest
	 */
	public static HttpServletRequest getServletRequest() {

		return request;
	}

	/**
	 * getServletResponse
	 * 
	 * @return response HttpServletResponse
	 */
	public static HttpServletResponse getServletResponse() {
		return response;
	}

	/**
	 * getSession
	 * 
	 * @return session Map
	 */
	public static Map getSession() {
		return session;
	}

	/**
	 * getParameters
	 * 
	 * @return parameters Map
	 */
	public static Map getParameters() {
		return parameters;
	}
	
	/**
	 * getAtribute
	 * 
	 * @param key
	 *            String
	 * @return Object Object
	 */
	public static Object getAtribute(String key) {
		return session.get(key);
	}

	/**
	 * getParameter
	 * 
	 * @return parameter Object
	 */
	public static Object getParameter(String key) {
		 return parameters.get(key);
	}
	// /**
	// * setConnectFlag
	// * @param connectFlag String
	// */
	// public static String getConnectFlag() {
	// return connectFlag;
	// }

	public String execute()throws Exception {

		// TODO Auto-generated method stub
		return ServerConsts.SUCCESS;
	}
}